<?php

namespace App\Models;

class Trades extends Base
{
    protected $table = 'trade';

    protected $fillable = [
        'id','name','created_at','sort'
    ];

    /**
     * 获取列表
     * @return mixed
     */
    protected function getList(){
  //      $lists = $this->get()->order('sort', 'desc')->toArray();
        $lists = $this->select("*")->orderBy('sort', 'asc')->get()->toArray();
      //  $menus = $this->toFormatTree($lists,'name');
        return $lists;
    }

    /**
     * 获取级联列表
     * @return mixed
     */
    protected function getCascaderList(){
        $lists = $this->where('status','<>',-1)->get(['id as value','name as label','pid'])->toArray();
        return $this->listToTree($lists, 'value');
    }

    /**
     * 获取级联列表-接口
     * @return mixed
     */
    protected function apiCascaderList(){
        $lists = $this->where('status','<>',-1)->get()->toArray();
        return $this->listToTree($lists, 'id');
    }

    /**
     * 获取分类上级
     * @return mixed
     */
    protected function getPid($id=0){
        return $this->where('id',$id)->where('status','<>',-1)->value('pid');
    }

    /**
     * 获取各级分类
     * @return mixed
     */
    protected function getcates($params, $fields = ['*']){
        return $this->select($fields)->where($params)->where('status','<>',-1)->get();
    }

}
